//https://leetcode.cn/problems/implement-queue-using-stacks/
package codeRandomThoughts.Test232用栈实现队列;

import java.util.Stack;

//二刷
public class MyQueue2 {
    private Stack<Integer> stackIn;
    private Stack<Integer> stackOut;

    public MyQueue2() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    public void push(int x) {
        stackIn.push(x);
    }

    public int pop() {
        //输出栈为空时补充数据
        if (stackOut.isEmpty()) {
            while (!stackIn.isEmpty()) {
                stackOut.push(stackIn.pop());
            }
        }
        return stackOut.pop();
    }

    public int peek() {
        int peek = this.pop();
        stackOut.push(peek);
        return peek;
    }

    public boolean empty() {
        return stackIn.isEmpty() && stackOut.isEmpty();
    }
}

